/*****************************************************
PROJECT: BRIDGE C2 SCRAP
JOB:
REQUESTOR:Rachel Gold
JIRA #:
ANALYST: Jean O'Malley
DATE: 8/4/2022
VERSION: 
LAST UPDATED: 
PEER REVIEWER: 

PROJECT DESCRIPTION: Use ASCEND approach to compare CRC, CVC and 
BC cancer prevention services in patients with
	No SDH Screening
	Documented Need
	Documented No Need
Stratified by SDH need: Food, Housing, Transportation
STUDY PERIOD: 7/1/2016-2/29/2020		

DETAILS (this file): 
CRC Outcome variables by SDH
	UTD at index 
	Type of last screen prior to index: None, FIT/FOBT, Imaging
	Months UTD over observation period
	Among Patients due 12 months before obs end, Receipt of screening order within 12 months
	Among patients with order, 
			receipt of order for imaging 
			receipt of screen while due(Poisson with months after due as offset)
		  	Receipt of FIT/FOBT order
			Receipt of Imaging/Order
Table 2.Columns Food Insecurity: Need/ No Need/ Not documented
Table 3 Columns Housing Insecurity: Need/ No Need/ Not documented
Table 4 Columns Transportation Insecurity: Need/ No Need/ Not documented
		

INPUT DATA:
SCRAP.CRC_outcomes;

OUTPUT DATA:
SCRAP.CRC_Table2_Food
SCRAP.CRC_Table3_Housing
SCRAP.CRC_Table4_Transportation


SECTIONS:
A. Dynamic variables and analysis file
B. Full cohort variables
	B1. UTD at index 
	B2. Imaging screen prior to index: 
	B3. Months UTD over observation period
	B4. Visits in year following Index (includes index visit
C.Among Patients due 12 months before obs end, 
	C1.Receipt of any screening order within 12 months
	C2.Receipt of order for imaging as first order

D.Among patients with order, 
	D1. receipt of screen while due(Poisson with months after due as offset)
E. Among patients receiving screen
	E1. Receipt of FIT/FOBT as first order
	E2. Receipt of Imaging/Order

****************************************************/
options compress=yes reuse=yes spool;
libname SCRAP "e:\\sasroot\BRIDGE C2\SCRAP\";
libname RD odbc noprompt="dsn=research_dev;Trusted_Connection=yes" bulkload=yes;

/****************************************************/
/***************************************************
A. Dynamic variables and analysis file
***************************************************/
%let cancer=CRC;
%Let covariates=female race_ethnic2 language_c  FPL_cat2 age_cat payor_type_research visit_cat;
%Let class=delivery_site_id female age_cat race_ethnic2 language_c  FPL_cat2 visit_cat payor_type_research;


data analysis;
set SCRAP.&cancer._analysis;
sdh_trans=sdh_transportation;
run;
proc sort data=analysis;
by delivery_site_id;
run;
proc freq data=analysis;
tables due female race_ethnic2 language_c  FPL_cat2 age_cat payor_type_research visit_cat;
run;

/************************************************
B. Full cohort variables
************************************************/
%macro tables;
/*	B1. UTD at index */


	proc genmod data=analysis;
	class &class &sdh /ref=first;
	model due=&sdh &covariates/link=log d=binomial type3;
	repeated subject=delivery_site_id/type=exch;
	LSmeans &sdh/ilink CL om;
	ods output LSmeans=due_&sdh lsmestimates=due_diffs_&sdh;
	lsmestimate &sdh '1 vs 2' -1 0 1/cl  om ilink;
	lsmestimate &sdh '3 vs 2' -1 1 0 /cl   om ilink;
	run;

	proc sort data=due_&sdh out=var1_&sdh (keep=&sdh Mu LowerMu UpperMu);
	by &sdh;
	run;
	data var1_&sdh(keep=Outcome &sdh prob_CI);
	set var1_&sdh;
	length Outcome $30;
	format mu2 lower2 upper2 4.1;
	Outcome="Up to Date &cancer screening";
	mu2=round(MU*100,0.1);
	mu_txt=put(mu2,4.1); 
	lower2=round(lowerMU*100,0.1);
	lower_txt=put(lower2,4.1);
	upper2=round(upperMU*100,0.1);
	upper_txt=put(upper2,4.1);
	prob_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;
	proc sort data=due_diffs_&sdh out=diff1_&sdh (keep= Probz label Mu Lowermu Uppermu);
	by label;
	run;

	data diff1_&sdh (keep=Outcome &sdh reference RR_CI probz);
	set diff1_&sdh;
	length Outcome $30 &sdh reference $20;
	format mu2 lower2 upper2 4.2;
	Outcome="Up to Date &cancer screening";
	reference='2_Negative Screen';
	if label='1 vs 2' then &SDH= '1_Positive Screen';
	if label='3 vs 2' then &SDH= '3_Never Screened';
	mu2=round(MU,0.01);
	mu_txt=put(mu2,4.2); 
	lower2=round(lowerMU,0.01);
	lower_txt=put(lower2,4.2);
	upper2=round(upperMU,0.01);
	upper_txt=put(upper2,4.2);
	RR_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;

	data var1_&sdh;
	merge var1_&sdh diff1_&sdh;
	by outcome &sdh;
	run;


	proc datasets library=work;
	delete due_diffs_&sdh diff1_&sdh  due_&sdh;
	quit;



/*	B2A. Any FIT/FOBT prior to index*/

	proc genmod data=analysis descending ;
	class &class &sdh /ref=first;
	model FIT_FOBT_prior=&sdh &covariates/link=log d=binomial type3;
	repeated subject=delivery_site_id/type=exch;
	LSmeans &sdh/ilink CL OM;
	ods output LSmeans=screen_&sdh lsmestimates=screen_diffs_&sdh;
	lsmestimate &sdh '1 vs 2' -1 0 1/cl  om ilink;
	lsmestimate &sdh '3 vs 2' -1 1 0 /cl   om ilink;
	run;

	proc sort data=screen_&sdh out=var2A_&sdh (keep=&sdh Mu LowerMu UpperMu);
	by &sdh;
	run;
	data var2A_&sdh(keep=Outcome &sdh prob_CI);
	set var2A_&sdh;
	length Outcome $30;
	Outcome="FIT/FOBT prior to Index";
	format mu2 lower2 upper2 4.1;

	mu2=round(MU*100,0.1);
	mu_txt=put(mu2,4.1); 
	lower2=round(lowerMU*100,0.1);
	lower_txt=put(lower2,4.1);
	upper2=round(upperMU*100,0.1);
	upper_txt=put(upper2,4.1);
	prob_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;
	proc sort data=screen_diffs_&sdh out=diff2A_&sdh (keep= Probz label Mu LowerMu UpperMu);
	by label;
	run;

	data diff2A_&sdh (keep=Outcome &sdh reference RR_CI probz);
	set diff2A_&sdh;
	length Outcome $30 &sdh reference $20;
	format mu2 lowermu uppermu 4.2;
	Outcome="FIT/FOBT prior to Index";
	reference='2_Negative Screen';
	if label='1 vs 2' then &SDH= '1_Positive Screen';
	if label='3 vs 2' then &SDH= '3_Never Screened';
	mu2=round(MU,0.01);
	mu_txt=put(mu2,4.2); 
	lower2=round(lowerMU,0.01);
	lower_txt=put(lower2,4.2);
	upper2=round(upperMU,0.01);
	upper_txt=put(upper2,4.2);
	RR_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;

	data var2A_&sdh;
	merge var2A_&sdh diff2A_&sdh;
	by outcome &sdh;
	run;


	proc datasets library=work;
	delete screen_diffs_&sdh diff2A_&sdh  screen_&sdh;
	quit;

/*	B2B. Any imaging prior to index*/

	proc genmod data=analysis descending;
	class &class &sdh /ref=first;
	model imaging_prior=&sdh &covariates/link=log d=binomial type3;
	repeated subject=delivery_site_id/type=exch;
	LSmeans &sdh/ilink CL OM;
	ods output LSmeans=screen_&sdh lsmestimates=screen_diffs_&sdh;
	lsmestimate &sdh '1 vs 2' -1 0 1/cl  om ilink;
	lsmestimate &sdh '3 vs 2' -1 1 0 /cl   om ilink;	run;

	proc sort data=screen_&sdh out=var2B_&sdh (keep=&sdh Mu LowerMu UpperMu);
	by &sdh;
	run;
	data var2B_&sdh(keep=Outcome &sdh prob_CI);
	set var2B_&sdh;
	length Outcome $30;
	Outcome="Imaging prior to Index";
	format mu2 lower2 upper2 4.1;

	mu2=round(MU*100,0.1);
	mu_txt=put(mu2,4.1); 
	lower2=round(lowerMU*100,0.1);
	lower_txt=put(lower2,4.1);
	upper2=round(upperMU*100,0.1);
	upper_txt=put(upper2,4.1);
	prob_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;

	proc sort data=screen_diffs_&sdh out=diff2B_&sdh (keep= Probz label Mu LowerMu UpperMu);
	by label;
	run;

	data diff2B_&sdh (keep=Outcome &sdh reference RR_CI probz);
	set diff2B_&sdh;
	length Outcome $30 &sdh reference $20;
	format mu2 lowermu uppermu 4.2;
	Outcome="Imaging prior to Index";
	reference='2_Negative Screen';
	if label='1 vs 2' then &SDH= '1_Positive Screen';
	if label='3 vs 2' then &SDH= '3_Never Screened';
	mu2=round(MU,0.01);
	mu_txt=put(mu2,4.2); 
	lower2=round(lowerMU,0.01);
	lower_txt=put(lower2,4.2);
	upper2=round(upperMU,0.01);
	upper_txt=put(upper2,4.2);
	RR_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;

	data var2B_&sdh;
	merge var2B_&sdh diff2B_&sdh;
	by outcome &sdh;
	run;


	proc datasets library=work;
	delete screen_diffs_&sdh diff2B_&sdh  screen_&sdh;
	quit;




/*	B3. Months UTD over observation period*/

	proc genmod data=analysis ;
	class &class &sdh /ref=first;
	model months_utd=&sdh &covariates/link=log d=negbin type3 offset=months_offset;
	repeated subject=delivery_site_id/type=exch;
	LSmeans &sdh/ilink CL OM;
	ods output LSmeans=mUTD_&sdh lsmestimates=mUTD_diffs_&sdh;
	lsmestimate &sdh '1 vs 2' -1 0 1/cl  om ilink;
	lsmestimate &sdh '3 vs 2' -1 1 0 /cl   om ilink;
	run;

	proc sort data=mUTD_&sdh out=var3_&sdh (keep=&sdh Mu LowerMu UpperMu);
	by &sdh;
	run;
	data var3_&sdh(keep=Outcome &sdh prob_CI);
	set var3_&sdh;
	length Outcome $30;
	Outcome="Percent Months UTD";
	format mu2 lower2 upper2 4.1;
	mu2=round(MU*100,0.1);
	mu_txt=put(mu2,4.1); 
	lower2=round(lowerMU*100,0.1);
	lower_txt=put(lower2,4.1);
	upper2=round(upperMU*100,0.1);
	upper_txt=put(upper2,4.1);
	prob_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;
	proc sort data=mUTD_diffs_&sdh out=diff3_&sdh (keep= Probz label mu Lowermu Uppermu);
	by label;
	run;

	data diff3_&sdh (keep=Outcome &sdh reference rr_CI probz);
	set diff3_&sdh;
	length Outcome $30 &sdh reference $20;
	format mu2 lowermu uppermu 4.2;
	Outcome="Percent Months UTD";
	reference='2_Negative Screen';
	if label='1 vs 2' then &SDH= '1_Positive Screen';
	if label='3 vs 2' then &SDH= '3_Never Screened';

	mu2=round(MU,0.01);
	mu_txt=put(mu2,4.2); 
	lower2=round(lowerMU,0.01);
	lower_txt=put(lower2,4.2);
	upper2=round(upperMU,0.01);
	upper_txt=put(upper2,4.2);
	RR_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;
	data var3_&sdh;
	merge var3_&sdh diff3_&sdh;
	by outcome &sdh;
	run;

	proc datasets library=work;
	delete mUTD_diffs_&sdh diff3_&sdh mUTD_diffs_&sdh mUTD_&sdh;
	quit;
/*	B4. Visits in year after index*/


	proc genmod data=analysis ;
	class &class &sdh /ref=first;
	model visits_first_yr=&sdh female race_ethnic2 language_c  FPL_cat2 
	age_cat payor_type_research /link=log d=negbin type3 ;
	repeated subject=delivery_site_id/type=exch;
	LSmeans &sdh/ilink CL OM;
	ods output LSmeans=visits_&sdh lsmestimates=visits_diffs_&sdh;
	lsmestimate &sdh '1 vs 2' -1 0 1/cl  om ilink;
	lsmestimate &sdh '3 vs 2' -1 1 0 /cl   om ilink;
	run;

	proc sort data=visits_&sdh out=var32_&sdh (keep=&sdh Mu LowerMu UpperMu);
	by &sdh;
	run;
	data var32_&sdh(keep=Outcome &sdh prob_CI);
	set var32_&sdh;
	length Outcome $30;
	Outcome="Visits in Year after Index";
	format mu2 lower2 upper2 4.1;
	mu2=round(MU,0.1);
	mu_txt=put(mu2,4.1); 
	lower2=round(lowerMU,0.1);
	lower_txt=put(lower2,4.1);
	upper2=round(upperMU,0.1);
	upper_txt=put(upper2,4.1);
	prob_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;
	proc sort data=visits_diffs_&sdh out=diff32_&sdh (keep= Probz label mu Lowermu Uppermu);
	by label;
	run;

	data diff32_&sdh (keep=Outcome &sdh reference rr_CI probz);
	set diff32_&sdh;
	length Outcome $30 &sdh reference $20;
	format mu2 lowermu uppermu 4.2;
	Outcome="Visits in Year after Index";
	reference='2_Negative Screen';
	if label='1 vs 2' then &SDH= '1_Positive Screen';
	if label='3 vs 2' then &SDH= '3_Never Screened';

	mu2=round(MU,0.01);
	mu_txt=put(mu2,4.2); 
	lower2=round(lowerMU,0.01);
	lower_txt=put(lower2,4.2);
	upper2=round(upperMU,0.01);
	upper_txt=put(upper2,4.2);
	RR_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;
	data var32_&sdh;
	merge var32_&sdh diff32_&sdh;
	by outcome &sdh;
	run;

	proc datasets library=work;
	delete visits_diffs_&sdh diff32_&sdh visits_diffs_&sdh visits_&sdh;
	quit;

/*	B5. PC Visits in year after index*/


	proc genmod data=analysis ;
	class &class &sdh /ref=first;
	model PC_visits_first_yr=&sdh female race_ethnic2 language_c  FPL_cat2 
	age_cat payor_type_research /link=log d=negbin type3 ;
	repeated subject=delivery_site_id/type=exch;
	LSmeans &sdh/ilink CL OM;
	ods output LSmeans=PCvisits_&sdh lsmestimates=PCvisits_diffs_&sdh;
	lsmestimate &sdh '1 vs 2' -1 0 1/cl  om ilink;
	lsmestimate &sdh '3 vs 2' -1 1 0 /cl   om ilink;
	run;

	proc sort data=PCvisits_&sdh out=var33_&sdh (keep=&sdh Mu LowerMu UpperMu);
	by &sdh;
	run;
	data var33_&sdh(keep=Outcome &sdh prob_CI);
	set var33_&sdh;
	length Outcome $30;
	Outcome="PC Visits in Year after Index";
	format mu2 lower2 upper2 4.1;
	mu2=round(MU,0.1);
	mu_txt=put(mu2,4.1); 
	lower2=round(lowerMU,0.1);
	lower_txt=put(lower2,4.1);
	upper2=round(upperMU,0.1);
	upper_txt=put(upper2,4.1);
	prob_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;

	proc sort data=PCvisits_diffs_&sdh out=diff33_&sdh (keep= Probz label mu Lowermu Uppermu);
	by label;
	run;

	data diff33_&sdh (keep=Outcome &sdh reference rr_CI probz);
	set diff33_&sdh;
	length Outcome $30 &sdh reference $20;
	format mu2 lowermu uppermu 4.2;
	Outcome="PC Visits in Year after Index";
	reference='2_Negative Screen';
	if label='1 vs 2' then &SDH= '1_Positive Screen';
	if label='3 vs 2' then &SDH= '3_Never Screened';

	mu2=round(MU,0.01);
	mu_txt=put(mu2,4.2); 
	lower2=round(lowerMU,0.01);
	lower_txt=put(lower2,4.2);
	upper2=round(upperMU,0.01);
	upper_txt=put(upper2,4.2);
	RR_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;
	data var33_&sdh;
	merge var33_&sdh diff33_&sdh;
	by outcome &sdh;
	run;


	proc datasets library=work;
	delete visits_diffs_&sdh diff33_&sdh visits_diffs_&sdh visits_&sdh;
	quit;

/********************************************************
/*C.Among Patients due 12 months before obs end, */
*********************************************************/;
data analysis2;
set analysis;
where one_year_due^=. and observation_end>=one_year_due
and time_to_screen < months_in_study;
run;
	



/*	C1.Receipt of any screening order within 12 months*/


	proc genmod data=analysis2 descending;
	class &class &sdh /ref=first;
	model order_1y=&sdh &covariates/link=log d=binomial type3;
	repeated subject=delivery_site_id/type=exch;
	LSmeans &sdh/ilink CL diff OM;
	ods output LSmeans=order_&sdh lsmestimates=order_diffs_&sdh;
	lsmestimate &sdh '1 vs 2' -1 0 1/cl  om ilink;
	lsmestimate &sdh '3 vs 2' -1 1 0 /cl   om ilink;
	run;

	proc sort data=order_&sdh out=var4_&sdh (keep=&sdh Mu LowerMu UpperMu);
	by &sdh;
	run;
	data var4_&sdh(keep=Outcome &sdh prob_CI);
	set var4_&sdh;
	length Outcome $30;
	Outcome="Order within 1 year of due";
	format mu2 lower2 upper2 4.1;
	mu2=round(MU*100,0.1);
	mu_txt=put(mu2,4.1); 
	lower2=round(lowerMU*100,0.1);
	lower_txt=put(lower2,4.1);
	upper2=round(upperMU*100,0.1);
	upper_txt=put(upper2,4.1);
	prob_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;
	proc sort data=order_diffs_&sdh out=diff4_&sdh (keep= Probz  label Mu LowerMu UpperMu);
	by label;
	run;

	data diff4_&sdh (keep=Outcome &sdh reference RR_CI probz);
	set diff4_&sdh;
	length Outcome $30 &sdh reference $20;
	format mu2 lower2 upper2 4.2;
	Outcome="Order within 1 year of due";
	reference='2_Negative Screen';
	if label='1 vs 2' then &SDH= '1_Positive Screen';
	if label='3 vs 2' then &SDH= '3_Never Screened';
	mu2=round(mu,0.1);
	mu_txt=put(mu2,4.2); 
	lower2=round(lowerMu,0.1);
	lower_txt=put(lower2,4.2);
	upper2=round(upperMu,0.1);
	upper_txt=put(upper2,4.2);
	RR_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;


	data var4_&sdh;
	merge var4_&sdh diff4_&sdh;
	by outcome &sdh;
	run;


	proc datasets library=work;
	delete order_diffs_&sdh diff4_&sdh  order_&sdh;
	quit;






/******************************************
/*D.Among patients with order, */
/******************************************/;
/*D.1. Receipt of Imaging order*/

	data analysis3;
	set analysis2;
	where order_1y=1;
	run;
	proc freq data=analysis3;
	tables imaging_order;
	run;

	proc genmod data=analysis3 descending;
	class &class &sdh /ref=first;
	model imaging_order=&sdh &covariates/link=log d=binomial type3;
	repeated subject=delivery_site_id/type=exch;
	LSmeans &sdh/ilink CL OM;
	ods output LSmeans=imaging_order_&sdh lsmestimates=imaging_diffs_&sdh;
	lsmestimate &sdh '1 vs 2' -1 0 1/cl  om ilink;
	lsmestimate &sdh '3 vs 2' -1 1 0 /cl   om ilink;	run;

	proc sort data=imaging_order_&sdh out=var5_&sdh (keep=&sdh Mu LowerMu UpperMu);
	by &sdh;
	run;
	data var5_&sdh(keep=Outcome &sdh prob_CI);
	set var5_&sdh;
	length Outcome $30;
	Outcome="Screening order for imaging";
	format mu2 lower2 upper2 4.1;
	mu2=round(mu*100,0.1);
	mu_txt=put(mu2,4.1); 
	lower2=round(lowermu*100,0.1);
	lower_txt=put(lower2,4.1);
	upper2=round(uppermu*100,0.1);
	upper_txt=put(upper2,4.1);
	prob_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;
	proc sort data=imaging_diffs_&sdh out=diff5_&sdh (keep= label probz Mu LowerMu UpperMu);
	by label;
	run;

	data diff5_&sdh (keep=Outcome &sdh reference RR_CI probz);
	set diff5_&sdh;
	length Outcome $30 &sdh reference $20;
	Outcome="Screening order for imaging";
	format mu2 lower2 upper2 4.2;
		reference='2_Negative Screen';
	if label='1 vs 2' then &SDH= '1_Positive Screen';
	if label='3 vs 2' then &SDH= '3_Never Screened';
	mu2=round(mu*100,0.1);
	mu_txt=put(mu2,4.2); 
	lower2=round(lowermu,0.1);
	lower_txt=put(lower2,4.2);
	upper2=round(uppermu,0.1);
	upper_txt=put(upper2,4.2);
	RR_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;

	data var5_&sdh;
	merge var5_&sdh diff5_&sdh;
	by outcome &sdh;
	run;


	proc datasets library=work;
	delete imaging_diffs_&sdh diff5_&sdh imaging_order_&sdh;
	quit;


/*	D2. receipt of any screen*/
	

	proc genmod data=analysis3 descending;
	class &class &sdh /ref=first;
	model screen_1yr=&sdh &covariates/link=log d=binomial type3;
	repeated subject=delivery_site_id/type=exch;
	LSmeans &sdh/ilink CL OM;
	ods output LSmeans=screen_&sdh lsmestimates=screen_diffs_&sdh;
	lsmestimate &sdh '1 vs 2' -1 0 1/cl  om ilink;
	lsmestimate &sdh '3 vs 2' -1 1 0 /cl   om ilink;
	run;

	proc sort data=screen_&sdh out=var6_&sdh (keep=&sdh Mu LowerMu UpperMu);
	by &sdh;
	run;
	data var6_&sdh(keep=Outcome &sdh prob_CI);
	set var6_&sdh;
	length Outcome $30;
	Outcome="Completed CRC Screen";
	mu2=round(Mu*100,0.1);
	mu_txt=put(mu2,4.1); 
	lower2=round(lowerMu*100,0.1);
	lower_txt=put(lower2,4.1);
	upper2=round(upperMu*100,0.1);
	upper_txt=put(upper2,4.1);
	prob_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;
	proc sort data=screen_diffs_&sdh out=diff6_&sdh (keep= label probz Mu LowerMu UpperMu);
	by label;
	run;

	data diff6_&sdh (keep=Outcome &sdh reference RR_CI probz);
	set diff6_&sdh;
	length Outcome $30 &sdh reference $20;
	Outcome="Completed CRC Screen";
	format mu2 lower2 upper2 4.2;
		reference='2_Negative Screen';
	if label='1 vs 2' then &SDH= '1_Positive Screen';
	if label='3 vs 2' then &SDH= '3_Never Screened';
	mu2=round(mu,0.1);
	mu_txt=put(mu2,4.2); 
	lower2=round(lowermu,0.1);
	lower_txt=put(lower2,4.2);
	upper2=round(uppermu,0.1);
	upper_txt=put(upper2,4.2);
	RR_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');
	run;

	data var6_&sdh;
	merge var6_&sdh diff6_&sdh;
	by outcome &sdh;
	run;

	proc datasets library=work;
	delete screen_diffs_&sdh diff6_&sdh  screen_&sdh;
	quit;

/*E. Among patients receiving screen*/
/*	data analysis4;*/
/*	set analysis3;*/
/*	where screen_1yr=1;*/
/*	run;*/
/*	proc freq data=analysis3;*/
/*	tables imaging_screen*&sdh/norow nopercent missing;*/
/*	run;*/


/*	E1. Receipt of Imaging*/
/**/
/*	proc genmod data=analysis4 descending;*/
/*	class &class &sdh /ref=first;*/
/*	model imaging_screen=&sdh &covariates/link=log d=binomial type3;*/
/*	repeated subject=delivery_site_id/type=exch;*/
/*	LSmeans &sdh/ilink CL OM;*/
/*	ods output LSmeans=imaging_&sdh lsmestimates=imaging_diffs_&sdh;*/
/*	lsmestimate &sdh '2 vs 1' 1 0 -1/cl ilink OM;*/
/*	lsmestimate &sdh '3 vs 1' 0 1 -1/cl ilink OM;*/
/*	run;*/
/**/
/*	proc sort data=imaging_&sdh out=var7_&sdh (keep=&sdh Mu LowerMu UpperMu);*/
/*	by &sdh;*/
/*	run;*/
/*	data var7_&sdh(keep=Outcome &sdh prob_CI);*/
/*	set var7_&sdh;*/
/*	length Outcome $30;*/
/*	Outcome="Completed Imaging Screen";*/
/*	mu2=round(Mu*100,0.1);*/
/*	mu_txt=put(mu2,4.1); */
/*	lower2=round(lowerMu*100,0.1);*/
/*	lower_txt=put(lower2,4.1);*/
/*	upper2=round(upperMu*100,0.1);*/
/*	upper_txt=put(upper2,4.1);*/
/*	prob_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');*/
/*	run;*/
/*	proc sort data=imaging_diffs_&sdh out=diff7_&sdh (keep= Mu LowerMu UpperMu);*/
/*	by label;*/
/*	run;*/
/**/
/*	data diff7_&sdh (keep=Outcome &sdh reference RR_CI probz);*/
/*	set diff7_&sdh;*/
/*	length Outcome $30 &sdh reference $20;*/
/*	Outcome="Completed Imaging Screen";*/
/*	format mu2 lower2 upper2 4.2;*/
/*	reference='1_Positive Screen';*/
/*	if label='2 vs 1' then &SDH= '2_Negative Screen';*/
/*	if label='3 vs 1' then &SDH= '3_Never Screened';*/
/*	mu2=round(mu,0.1);*/
/*	mu_txt=put(mu2,4.2); */
/*	lower2=round(lowermu,0.1);*/
/*	lower_txt=put(lower2,4.2);*/
/*	upper2=round(uppermu,0.1);*/
/*	upper_txt=put(upper2,4.2);*/
/*	RR_CI=cat(mu_txt,' (',lower_txt,', ',upper_txt,')');*/
/*	run;*/
/**/
/*	data var7_&sdh;*/
/*	merge var7_&sdh diff7_&sdh;*/
/*	by outcome &sdh;*/
/*	run;*/
/**/
/*	proc datasets library=work;*/
/*	delete screen_diffs_&sdh diff7&sdh  screen_&sdh;*/
/*	quit;*/
;
	data Table_&sdh;
	set var1_&sdh 
		var2A_&sdh
		var2B_&sdh
		var3_&sdh
		var32_&sdh
		var33_&sdh
		var4_&sdh
		var5_&sdh
		var6_&sdh
/*		var7_&sdh*/

;
	run;
*reorder columns;
proc sql;
create table tableb as
select outcome,
&sdh,
prob_CI,
reference,
rr_ci,
probz
from Table_&sdh;
quit;

data scrap.Table_&sdh.&cancer;
set tableb;
run;
%mend;

%let SDH=SDH_Food; 
%tables;


%let SDH=SDH_Housing;
%tables;

%Let SDH=SDH_Trans;
%tables;
proc datasets library=work;
save analysis;
quit;


proc freq data=scrap.crc_analysis;
tables SDH_food--sdh_transportation;
run;
proc freq data=scrap.crc_analysis;
where due=0;
tables SDH_food--sdh_transportation;
run;
proc freq data=scrap.crc_analysis;
where one_year_due^=. and observation_end>=one_year_due
and time_to_screen < months_in_study;
tables SDH_food--sdh_transportation;
run;

proc freq data=scrap.crc_analysis;
where one_year_due^=. and observation_end>=one_year_due
and time_to_screen < months_in_study and order_1y=1;
tables SDH_food--sdh_transportation;
run;


proc print data=scrap.table_sdh_foodcrc;
run;
proc print data=scrap.table_sdh_housingcrc;
run;
proc print data=scrap.table_sdh_transcrc;
run;